<?php
/**
* @Copyright Copyright (C) 2010- ... Andy Sharman
* @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
**/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin' );


class plgButtonCustomFields extends JPlugin
{
	function plgCustomFields( &$subject, $config )
	{
		parent::__construct( $subject, $config );

		// Do some extra initialisation in this constructor if required
	}

	/**
	 * Do something onAfterInitialise 
	 */
	function onDisplay($name)
    {  
    
		//if not inside article manager, don't show button.
		if (JRequest::getString('option') == 'com_content')
		{
			$get = JRequest::get();
			$article_id = $get['cid'][0];
			
			// Perform some action
			$button = new JObject();
			
			$button->set('options', "{handler: 'iframe', size: {x: 500, y: 500}}");
			$link = "index.php?option=com_customfields&task=add&article_id=$article_id&tmpl=component";
			
			$button->set('modal', true);
			$button->set('class', 'modal');
			$button->set('text', JText::_('Add custom fields'));
			$button->set('name', 'customfields');
			$button->set('link', $link);
							
			return $button;
		}
		else
		{
			return;
		}
	}
}